package com.briup.web.controller;

import com.briup.bean.Order;
import com.briup.bean.User;
import com.briup.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;


@Controller
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @GetMapping(value = {"/toOrder"})
    public String toOrder( HttpSession session, Model model){
        User user = (User) session.getAttribute("user");
        List<Order> orderList = orderService.findUserAllOrders(user.getId());
        System.out.println(orderList);
        model.addAttribute("orderList",orderList);
        return "order";
    }

    @GetMapping(value = {"/delOrder"})
    @ResponseBody
    public String delOrder(String orderId){
        orderService.deleteOrder(orderId);
        return "success";
    }
}
